package com.kadron.jobs;

import java.util.Date;
import java.util.TimerTask;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.TransactionPropagationType;
import org.jboss.seam.annotations.Transactional;
import org.jboss.seam.annotations.async.Asynchronous;
import org.jboss.seam.annotations.async.Expiration;
import org.jboss.seam.annotations.async.IntervalDuration;

@AutoCreate
@Transactional(TransactionPropagationType.REQUIRED)
@Scope(ScopeType.APPLICATION)
@Name(KJobSheduler.K_NAME)
public class KJobSheduler {
	
	private static final Log log = LogFactory.getLog(KJobSheduler.class);
	public static final String K_NAME = "kJobWorker";
	
	@Asynchronous
	public void shedule(TimerTask task, @Expiration Date expire, @IntervalDuration Long duration) {
		if (log.isInfoEnabled()) {
			log.info("Processing task: " + task.getClass().getSimpleName()+", time: " +System.currentTimeMillis());			
		}
		task.run();
	}
	
}
